package sgd.tp2.client.net.udp;

import java.io.IOException;
import java.net.DatagramPacket;

import javax.xml.bind.JAXBException;

import sgd.tp2.api.cdr.CDR;
import sgd.tp2.api.cdr.CDRHandlerJSON;
import sgd.tp2.api.net.CDRFormatType;

public class UDPClientJSON extends UDPClient {

	public UDPClientJSON(CDRFormatType cdrFormatType, String serverAddress, int serverPort) {
		super(cdrFormatType, serverAddress, serverPort);
	}

	public UDPClientJSON(CDRFormatType cdrFormatType, String serverAddress, int serverPort,
			int packetSize) {
		super(cdrFormatType, serverAddress, serverPort, packetSize);
	}

	@Override
	public void sendMessage() throws IOException, JAXBException {
		byte[] dataToSend = CDRHandlerJSON.getJSONFromCDR(CDR.getWithRandomData()).getBytes();

		DatagramPacket packet = new DatagramPacket(dataToSend, dataToSend.length, serverIPAddress,
				serverPort);
		socket.send(packet);
	}
}
